import { S, U, getRequestId, mapField } from '../../lib/backend'
import Q from 'q'
import axios from 'axios'
import env from '../../config/common'
import { UPDATE_INVALID_CUSTOM_QUERY_CONDITION } from '../mutation-types'

export default {
  getInvalidCustomData ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.user.site_id + '/invalid/custom/list'
    return axios.get(URL + '?' + U(info))
  },
  emptyQueryCondition ({ commit }, data) {
    commit(UPDATE_INVALID_CUSTOM_QUERY_CONDITION, data)
  },
  getInvalidCustomRuleList ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.user.site_id + '/invalid_custom/distribute_rule/list'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/[token]/sites/[site_id]/invalid_custom/distribute_rule/list'
    return axios.get(URL + '?' + U(info))
  },
  getInvalidCustomRule ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.user.site_id + '/invalid_custom/distribute_rule'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/[token]/sites/[site_id]/invalid_custom/distribute_rule/list'
    return axios.get(URL + '?' + U(info))
  },
  saveInvalidCustomRuleList ({ dispatch, commit, state, rootState }, info) {
    const URL = env.CRM_API_HOST + '/admin/' + rootState.auth.user.token + '/sites/' + rootState.auth.user.site_id + '/save/invalid_custom/distribute_rule'
    // const URL = 'http://rap2api.taobao.org/app/mock/2717/GET/admin/%7Btoken%7D/sites/%7Bsite_id%7D/save/invalid_custom/distribute_rule'
    return axios.post(URL, info)
  },
}
